package com.yuelao.yuelao_backend.dto;

import lombok.Data;

import java.time.LocalDateTime;

@Data
public class MessageDTO {
    private Long id;
    private Long senderId;
    private String senderNickname;
    private String senderAvatar;
    private Long receiverId;
    private String receiverNickname; // 私聊时
    private String receiverAvatar;   // 私聊时
    private String groupName;        // 群聊时
    private String messageType;
    private String contentType;
    private String content;
    private String mediaUrl;
    private String fileName;
    private Long fileSize;
    private String thumbnailUrl;
    private Integer duration;
    private LocalDateTime sentAt;
    private Boolean isRead;
    
    /**
     * 获取格式化的文件大小
     */
    public String getFormattedFileSize() {
        if (fileSize == null) {
            return "0 B";
        }
        
        if (fileSize < 1024) {
            return fileSize + " B";
        } else if (fileSize < 1024 * 1024) {
            return String.format("%.1f KB", fileSize / 1024.0);
        } else if (fileSize < 1024 * 1024 * 1024) {
            return String.format("%.1f MB", fileSize / (1024.0 * 1024.0));
        } else {
            return String.format("%.1f GB", fileSize / (1024.0 * 1024.0 * 1024.0));
        }
    }
}